home *** CD-ROM | disk | FTP | other *** search
- // REPORT.CPP - output of racing and other data to a file - M. Timin, March 1995
- // for RARS version 0.4
-
- /*
- * Modified:
- *
- * - l. 54 : Added typecast to remove warning that char != int.
- */
-
- #include <fstream.h>
- #include <iostream.h>
- #include <string.h>
- #include <iomanip.h>
- #include "track.h"
- #include "car.h"
-
- ofstream fout("race.out");
-
- extern char* nam_ptr[]; // The original array of robot names
-
- static int how_many;
-
- int find_name(char* name) // find this name in original array, nam_ptr
- {
-
- int i, cmp;
- for(i=0; i<MAXCARS; i++) {
- cmp = strcmp(name, nam_ptr[i]);
- if(!cmp)
- break;
- }
- if(i == MAXCARS)
- return -1; // -1 is returned if name is not found,
- else
- return i; // else returned value will be 0 - 15
- }
-
- /* there is no help file on the Amiga version */
- void print_help_file(void)
- {
- return;
- }
-
- /* the ram reporting function was very silly, so I removed it altogether */
- void RAM_report(void)
- {
- return;
- }
-
- void output_names(int cars, char** names)
- {
- for(int i=0; i<cars; i++) {
- if(i < cars - 1) {
- fout << names[i] << ", ";
- if(i == 7)
- fout << endl;
- }
- else
- fout << "and " << names[i] << "." << endl;
- }
- }
-
- void report_overall(int cars, int laps, char** names)
- {
- how_many = cars; // store the car count for later use
-
- fout << cars << " cars for " << laps << " laps. The track was ";
- fout << trackfile << ". The drivers were:" << endl;
- output_names(cars, names);
- fout << endl;
- }
-
- void report_results(int race, int* order, char** names, Car** pcar)
- {
- int i, k, m, who;
- const int points[] = { 10, 6, 4, 3, 2, 1 };
- static int accum_pts[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
- fout << " results of race " << race << ":" << endl;
- fout << "starting positions:" << endl;
-
- output_names(how_many, names);
-
- // The places:
- m = how_many;
- for(i=0; i<m; i++) {
- k = order[i];
- who = find_name(names[k]); // Where is the kth car in the original list?
- if(i < 6)
- accum_pts[who] += points[i];
- fout << "place " << i+1 << " ";
- fout << setw(10) << setiosflags(ios::left) << names[k];
- fout << setprecision(2);
- fout << " average speed " << pcar[k]->speed_avg * MPH_FPS;
- fout << " mph" << " " << accum_pts[who];
- fout << " points accumulated" << endl;
- }
- fout << endl;
- }
-